package com.project2.controller;


import com.project2.bean.CommonData;
import com.project2.bean.PageBo;
import com.project2.bean.ResultVo;
import com.project2.bean.bo.KeyWordCreateBO;
import com.project2.bean.po.MarketKeyword;
import com.project2.service.KeyWordService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: cc
 * @Date: 2022-08-13 17:08
 * @Description: 关键字模块
 */
@RestController
@RequestMapping("admin/keyword")
public class AdminKeywordController {

    @Autowired
    KeyWordService keywordService;

    /**
     * 显示所有关键字list
     * @param keyword  模糊查询 关键字
     * @param url       模糊查询 路径
     * @param pageBo
     * @return
     */

    @RequiresPermissions("admin:keyword:list")
    @GetMapping("list")
    public ResultVo keywordInfo(String keyword, String url, PageBo pageBo){

     CommonData data = keywordService.getKeywordInfo(keyword,url,pageBo);

             return ResultVo.ok(data);
    }


    /**
     * 创建关键字
     * @param keyWordCreateBO
     * @return
     */
    @RequiresPermissions("admin:keyword:create")
    @PostMapping("create")
    public ResultVo keywordCreate(@RequestBody KeyWordCreateBO keyWordCreateBO){

        MarketKeyword keyword = keywordService.keywordCreate(keyWordCreateBO);


        return ResultVo.ok(keyword);

    }

    /**
     * 逻辑删除
     * @param marketKeyword
     * @return
     */
    @RequiresPermissions("admin:keyword:delete")
    @PostMapping("delete")
    public ResultVo keywordDelete(@RequestBody MarketKeyword marketKeyword){


      int delete = keywordService.keywordDelete(marketKeyword);

      if (delete != 1){
          return ResultVo.wrong("delete error");
      }

      return ResultVo.ok();
    }


    /**
     * 修改关键字
     * @param marketKeyword
     * @return
     */
    @RequiresPermissions("admin:keyword:update")
    @PostMapping("update")
    public ResultVo keywordUpdate(@RequestBody MarketKeyword marketKeyword){


        MarketKeyword keyword = keywordService.keywordUpdate(marketKeyword);


        return ResultVo.ok(keyword);
    }
}
